package com.weipu.common.facade.model.config;

import java.io.Serializable;

import com.weipu.common.facade.model.status.AppRunStatus;
import com.weipu.common.util.StringUtil;

public class StartupConfig implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -3164343609109830236L;
    
    private AppRunStatus runType;//程序运行状态
    
    private long startupDelay; //启动延时(毫秒)
    
    private boolean enablePreLoadCategory;//启动时是否允许预加载栏目数据
    
    private boolean enablePreLoadProduct;//启动时是否允许预加载(挂牌)产品数据
    
    public boolean isEnablePreLoadCategory()
    {
        return enablePreLoadCategory;
    }
    
    public void setEnablePreLoadCategory(boolean enablePreLoadCategory)
    {
        this.enablePreLoadCategory = enablePreLoadCategory;
    }
    
    public boolean isEnablePreLoadProduct()
    {
        return enablePreLoadProduct;
    }
    
    public void setEnablePreLoadProduct(boolean enablePreLoadProduct)
    {
        this.enablePreLoadProduct = enablePreLoadProduct;
    }
    
    public AppRunStatus getRunStatus()
    {
        if (null == runType)
        {
            //默认值为第一次安装
            String runTypeCfg =
                StringUtil.getConfig("AppRunType", String.valueOf(AppRunStatus.FIRST_INSTALL.valueOf()));
            
            runType = AppRunStatus.getRunTypeByStatus(StringUtil.parsetInt(runTypeCfg, 0));
        }
        return runType;
    }
    
    public void setRunStatus(AppRunStatus runType)
    {
        if (null != runType)
        {
            //保存配置到本地文件配置
            StringUtil.saveConfig("AppRunType", String.valueOf(runType.valueOf()));
            
        }
        this.runType = runType;
    }
    
    public long getStartupDelay()
    {
        return startupDelay;
    }
    
    public void setStartupDelay(long startupDelay)
    {
        this.startupDelay = startupDelay;
    }
    
    @Override
    public int hashCode()
    {
        return toString().hashCode();
    }
    
    @Override
    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        
        sb.append("startupDelay: ").append(startupDelay).append('\n');
        
        sb.append("enablePreLoadCategory: ").append(enablePreLoadCategory).append('\n');
        
        sb.append("enablePreLoadProduct: ").append(enablePreLoadProduct).append('\n');
        
        sb.append("runType: ").append(runType);
        
        return sb.toString();
        
    }
}
